package com.demo.model.entity;

import com.demo.annotation.UpdatePlus;
import com.demo.annotation.UpdateReplace;
import com.demo.constant.EsIndexConstants;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;

import java.math.BigDecimal;

/**
 * @author shenguangyang
 */
@Setting(shards = 3,replicas = 1)
@Document(indexName = EsIndexConstants.BOOK)
public class Book {
    @Id
    private String id;
    @Field(analyzer = "ik_max_word", type = FieldType.Text)
    private String name;
    @Field(analyzer = "ik_max_word", type = FieldType.Text)
    private String author;
    @Field(type = FieldType.Double)
    @UpdatePlus
    private BigDecimal price;
    @Field(analyzer = "ik_max_word", type = FieldType.Text)
    private String content;

    /** 标签 */
    @Field(analyzer = "ik_smart", type = FieldType.Text)
    @UpdateReplace
    private String tags;

    /** 书的销量 */
    @Field(type = FieldType.Integer)
    private Integer sales;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public Integer getSales() {
        return sales;
    }

    public void setSales(Integer sales) {
        this.sales = sales;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    @Override
    public String toString() {
        return "Book{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", content='" + content + '\'' +
                ", tags='" + tags + '\'' +
                ", sales=" + sales +
                '}';
    }
}
